/**
 * Copyright (c) 2019, ShangHai YTO Co., Ltd.
 * All right reserved.
 *
 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF YTO
 * CO., LTD.  THE CONTENTS OF THIS FILE MAY NOT BE DISCLOSED
 * TO THIRD PARTIES, COPIED OR DUPLICATED IN ANY FORM, IN WHOLE OR IN PART,
 * WITHOUT THE PRIOR WRITTEN PERMISSION OF YTO
 * CO., LTD.
 */
package org.sc.xl.easyexcel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.io.FileUtils;
import org.apache.poi.ss.usermodel.PaperSize;
import org.apache.poi.ss.usermodel.PrintSetup;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.util.List;

/**
 * @description: TODO 请在此添加描述
 * @reason: TODO ADD REASON(可选)
 * @author FXL
 *
 * @date 2024/10/19 11:11 
 * @since JDK 1.8
 */
public class EasyExcelMain {

    //	221 160 221

    public static void main(String[] args) throws Exception {

        String jsonData = FileUtils.readFileToString(new File("/Users/fxl/IdeaProjects/self-pro/tools/src/main/java/org/sc/xl/easyexcel/init_data.json"));
//        String jsonData = FileUtils.readFileToString(new File("D:\\project\\self-pro\\tools\\target\\classes\\org\\sc\\xl\\easyexcel\\init_data.json"));
//        String jsonData = FileUtils.readFileToString(new File("D:\\project\\self-pro\\tools\\src\\main\\java\\org\\sc\\xl\\easyexcel\\init_data.json"));
        List<IndexOverviewResult> indexOverviewResults = JSONArray.parseArray(jsonData, IndexOverviewResult.class);
//        indexOverviewResults.get(3).setArrow(FileUtils.readFileToByteArray(new File("D:\\project\\self-pro\\tools\\src\\main\\java\\org\\sc\\xl\\easyexcel\\上升.png")));

//        EasyExcel.write("C:\\Users\\admin\\Desktop\\gpt\\demo.xlsx", IndexOverviewResult.class)
        EasyExcel.write("/Users/fxl/Downloads/a.xlsx" , IndexOverviewResult.class)
                .inMemory(true)
                .sheet("Sheet1")
                .head(IndexOverviewHeadConstant.headList)
                .registerWriteHandler(new CustomSheetStyleHandler())
                .registerWriteHandler(new CustomCellMergeHandler(2, new int[]{1, 2}))
                .registerWriteHandler(new CustomCellHeightHandler())
                .registerWriteHandler(new CustomCellWidthHandler())
                .registerWriteHandler(new CustomCellStyleHandler())
                .registerWriteHandler(new CustomModifyHandler())
                .doWrite(indexOverviewResults);
    }

}
